home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/perl
- #/****************************************************
- #**
- #** SOURCE NAME | postnews (Post News)
- #** |
- #** SYNOPSIS | postnews [-h hostname] [-p port] [-W timeout]
- #** |
- #** DESCRIPTION | postnews goes to a specified NNTP server
- #** | and posts the article from standard input
- #** | Server can be specified (in order of precedence):
- #** | * in -h <host> option
- #** | * in NNTPSERVER environment variable
- #** | * output of command 'domainname' by default
- #** |
- #** CHANGES | Programmer: Date: Reason/Comments
- #** | Pavel Klark 05-06-94 VERSION 1.0 (postnews)
- #** |
- #****************************************************/
-
- require 'sys/socket.ph'; # The way I coded the sockets is this necessary?
- require 'getopts.pl';
- # Valid options are:
- # -p portnumber : Port to connect to; default 119
- # -h host : Server host to connect to
- # -W timeout : Timeout wait period for response, sec.; default 900 (= 15min)
- $opt_h = $ENV{'NNTPSERVER'};
- $domain = `domainname`;
- chop $domain;
- $opt_h = substr($domain,1) unless $opt_h;
- $opt_p = 119;
- $opt_W = 900;
- &Getopts ('h:p:W:');
-
- $VERSION = '2.0';
-
- $port = $opt_p; # For NNTP
- # HOSTNAME for the server...
- $host = $opt_h;
- # Pack format...
- $sockaddr = 'S n a4 x8';
-
- $waittime = $opt_W;
-
- $DOMAIN = &AF_INET;
- $STYLE = &SOCK_STREAM;
-
- $rin = $rout = '';
-
- ($name, $aliases, $proto) = getprotobyname('tcp');
- ($name, $aliases, $type, $len, $hostaddr) = gethostbyname($host);
-
- $sock = pack($sockaddr, $DOMAIN, $port, $hostaddr);
-
- print "Connecting to $host...";
- $| = 1;
- socket(S, $DOMAIN, $STYLE, $proto) || die $!;
- connect(S, $sock) || die $!;
- select(S); $| = 1; select(STDOUT);
- #set up for select
- vec($rin, fileno(S), 1) = 1;
- #this select will block until the server gives us something.
- $nfound = select($rout=$rin, undef, undef, $waittime);
- if ($nfound == 0)
- {
- print "Socket timed out...\n";
- exit 1;
- }
- $_ = <S>; #Read one line to see if we got a good connection.
- if ($_ !~ /^2../)
- {
- print "\n";
- print;
- die "News server '$host' unavailable";
- }
- print "ok\n";
- print(S "post\n");
- #this select will block until the server gives us something.
- $nfound = select($rout=$rin, undef, undef, $waittime);
- if ($nfound == 0)
- {
- print "Socket timed out...\n";
- exit 1;
- }
- $_ = <S>; #Make sure the posting command worked...
- ($stat, $num, $first, $last) = split;
- if( $stat !~ /^3../ )
- {
- print;
- }
- print "Posting article...\n";
- while (<STDIN>) {
- print;
- s/^\./../;
- print(S $_);
- }
- print(S ".\n");
- select(S);$| = 1;select(STDOUT);
- #this select will block until the server gives us something.
- $nfound = select($rout=$rin, undef, undef, $waittime);
- if ($nfound == 0)
- {
- print "Socket timed out...";
- exit 1;
- }
- $_ = <S>;
- print;
- print(S "quit\n");
- close(S);
-